#include "Man.h"

Man::Man():

    _lives(0),
    _score(0)

{}

void Man::initialise()
{
    LifeForm::initialise(650,350,0,0,10,10,MAN);
    _lives = 3;
}

void Man::update()
{
    LifeForm::update();

    //prevent man from moving outside the bounds of the game
    if (_pos_x < 0)
    {
        _pos_x = 0;
    }
    else if (_pos_x > (displayWidth-50))
    {
        _pos_x = displayWidth-50;
    }

    if (_pos_y < 100)
    {
        _pos_y = 100;
    }
    else if (_pos_y > (displayHeight-50))
    {
        _pos_y = displayHeight-50;
    }
}

void Man::lose_life()
{
    _lives --;

    _pos_x = 650;   //reset man to starting position
    _pos_y = 350;

    if ( _lives <= 0 )  //man dies if no lives left
    {
        set_alive(false);
    }
}

bool Man::check_collision(int monster_pos_x, int monster_pos_y)
{
    if ( (_pos_x < monster_pos_x+50)       &&      //monster approach from left
         (_pos_x+50 > monster_pos_x+50 )   &&
         (_pos_y == monster_pos_y)          )
    {
        return true;
    }

    else if ( (_pos_x < monster_pos_x)     &&
              (_pos_x+50 > monster_pos_x)  &&      //monster approach from righ
              (_pos_y == monster_pos_y)     )
    {
        return true;
    }

    else if ( (_pos_x == monster_pos_x)     &&      //monster approach from above
              (_pos_y < monster_pos_y+50)   &&
              (_pos_y+50 > monster_pos_y+50))
    {
        return true;
    }

    else if ( (_pos_x == monster_pos_x)     &&      //monster approach from below
              (_pos_y+50 > monster_pos_y)   &&
              (_pos_y < monster_pos_y)  )
    {
        return true;
    }

    else return false;
}

int Man::get_lives()
{
    return _lives;
}

void Man::score_point()
{
    _score += 100;
}

int Man::get_score()
{
    return _score;
}

